// Copyright 2013 Petar Maymounkov
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package fuse

import (
	"syscall"
)

// An Error is a FUSE error.
type Error interface {
	errno() int32
}

const (
	// ENOSYS indicates that the call is not supported.
	ENOSYS = Errno(syscall.ENOSYS) // n/a

	// ESTALE is used by Serve to respond to violations of the FUSE protocol.
	ESTALE = Errno(syscall.ESTALE) // clash

	EACCES = Errno(syscall.EACCES) // exist
	ENOENT = Errno(syscall.ENOENT) // not exist

	EBUSY = Errno(syscall.EBUSY) // busy
	EBADF = Errno(syscall.EBADF) // gone

	EIO   = Errno(syscall.EIO)   // io
	EPERM = Errno(syscall.EPERM) // perm

	EINTR  = Errno(syscall.EINTR)  // intr
	EINVAL = Errno(syscall.EINVAL) // clash

	// ETIMEDOUT
	// E2BIG
	// ENODEV
	// EAGAIN
	// ENOMEM
	// EISDIR, ENOTDIR
	// EPIPE
	// EROFS
)

// Errno implements Error using a syscall.Errno.
type Errno syscall.Errno

func (e Errno) errno() int32 {
	return int32(e)
}

func (e Errno) String() string {
	return syscall.Errno(e).Error()
}
